/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution264 {

    public static void main(String args[]) {
        Solution264 s = new Solution264();
        System.out.println(s.nthUglyNumber(11));
    }

    public int nthUglyNumber(int n) {
        int[] k = new int[2000];
        int t2, t3, t5;
        t2 = t3 = t5 = 0;

        int idx = 1;
        k[0] = 1;
        while (idx < n) {
            int kmin = Math.min(2 * k[t2], Math.min(3 * k[t3], 5 * k[t5]));
            k[idx ++] = kmin;
            if(2 * k[t2] == kmin){
                t2 ++;
            }
            if(3 * k[t3] == kmin){
                t3 ++;
            }
            if(5 * k[t5] == kmin){
                t5 ++;
            }
        }
        return k[n - 1];
    }
}
